//extern pascal void ShowIcon(short iconID, short pixels);
static void mypatch(void);
#define patchSize (526) // because of CodeWarrior asm limitations
#define HFSDispatchTrapNum 0x60
pascal long main(short message, short /*item*/, short /*numItems*/, short /*cPanelID*/, EventRecord */*theEvent*/, long cdevValue, DialogPtr /*cpDialog*/)
{
long resp;
if (cdevValue) {
switch (message) {
case initDev:
return cdevGenErr;
break;
case macDev:
// normally you shouldn't check against the System version but against individual features
// but in this case we want to know whether custom icons are used by the Finder
if (TrapAvailable(_Gestalt)) {
if (Gestalt(gestaltSystemVersion, &resp) == noErr)
if (resp >= 0x700) {
mypatch();
return 1;
}
}
// no _Gestalt => very old System (< 6.0.4)
return 0;
break;
}
}
return cdevValue;
}
asm void mypatch(void)
{
moveq #HFSDispatchTrapNum,d0 // patch HFSDispatch
_GetOSTrapAddress
move.l OurHFSDispatch,d0
cmp.l (a0),d0
// if the patch is already there do nothing
beq.s bad
lea oldHFSDispatch,a1
move.l a0,(a1)
subq.w #4,sp
move.l #'STR#',-(SP)
move.w #128,-(sp)
_Get1Resource
move.l (sp)+,d0
beq.s bad
lea stringH,a0
move.l d0,(a0) // remember string handle
move.l d0,-(sp)
_DetachResource
// move.l #(EndHFSDispatch-OurHFSDispatch),d0
move.l #patchSize,d0
_NewPtr //Sys
// this block is installed in the System heap anyway, because
// the Finder calls our cdev with the current zone set to the System zone
// (at least under 7.5.5!)
// in theory we should install everything in the Finder heap since it now
// belongs there; but since the Finder malfunctions when its heap is low
// (maybe the current zone is not set to the Finder zone for this reason)
// we refrain from forcing the Finder zone with GetZone/SetZone